//lay message khuyn mai show len
var timer = '';
function getContent(type){	
	openBoxFeedback('fb',360,550);	
	$.ajaxSetup({
	 	timeout: 10000
	});
	var content_feedback = $('#content_feedback').val();
	var captcha_feedback = $('#captcha_feedback').val();
	var verify_feedback = $('#verify_feedback').val();	
	var email_fb = $('#email_fb').val();
	var cate_fb = $('#cate_fb').val();		
	var datetime = new Date(); 
	var url = "/general/qna.38.fb."+datetime.getTime()+".html";
	$.post(url, { 
		   'type': type, 
		   'content': content_feedback,
		   'captcha': captcha_feedback,
		   'email_fb': email_fb,
		   'cate_fb': cate_fb,		   
		   'verify': verify_feedback
		},
		function(json){ 	
			if(json['flag'] == 1){
				$('#feedback').html(json['content']);
				if(json['succ'] == 1){
					timer = setTimeout("closeFeedback()",5000);
				}else{
					clearTimeout(timer);
					$('#cate_fb').focus();
				}
				return false;
			}
		},'json'
	);
}
function openFeedback(){
	getContent(0);
}
function closeFeedback(){
	$('#TB_overlay').hide();
	$('#feedback').html('');
}
function submitFeedback(){
	var content = $('#content_feedback').val();
	var email_fb = $('#email_fb').val();	
	if(trim_(email_fb) != ''){
		var re = /^([A-Za-z0-9\_\-]+\.)*[A-Za-z0-9\_\-]+@[A-Za-z0-9\_\-]+(\.[A-Za-z0-9\_\-]+)+$/;
		if (email_fb.search(re) == -1){		
			$('#fb_err').html('Email phản hồi không hợp lệ.');
			return false;
		}	
	}
	if(trim_(content) == ''){
		$('#fb_err').html('Mời bạn nhập ý kiến đóng góp của mình.');
		$('#content_feedback').val('')
		return false;
	}
	getContent(1);
}
function openBoxFeedback(opt,width,height){
	if (screen) {
		var leftPos = (screen.width / 2) - (width/2)
		var topPos = (screen.height / 2) - (height/2)
	}
	if(opt=='fb'){
		$('#p_feedback').css("left",leftPos);	
		$('#p_feedback').css("top",topPos);				
	}
	if(opt=='succ'){
		$('#box_succ_register').css("left",leftPos);	
		$('#box_succ_register').css("top",topPos);
		$('#box_succ_register').show();
	}
	if(opt=='verify'){
		$('#box_verify_info').css("left",leftPos);	
		$('#box_verify_info').css("top",topPos);
		$('#box_verify_info').show();
	}	
	$('#TB_overlay').show();
	setOverlay();
}
function setOverlay(){
	var screenW = 640, screenH = 480;
	if (parseInt(navigator.appVersion)>3) {
		screenW = screen.width;
		screenH = screen.height;	
	}
	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent) || /Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
		$('#TB_overlay').addClass('fullscreenFF');
	}else{
		$('#TB_overlay').css("width",screenW+'.px');	
		$('#TB_overlay').css("height",screenH+'.px');
	}
	
}
$(document).ready(function () {
	var product_id = $('#product_id').val();
	var product_url = $('#product_url').val();
	var product_name = $('#product_name').val();	
	var view_box = $('#view_box').val();	
	if(view_box == 2){
		openBoxFeedback('verify',882,550);
		return;
	}
	if(view_box == 1){
		openBoxFeedback('succ',882,550);
		if(product_id != 38){
			$('#is_product').show();
			var str = '<br/><a href="'+product_url+'" >Quay về trang '+product_name+'</a>';
			$('#is_product').html(str);	
		}
		
	}
});
function closeBoxSuccess(){
	$('#TB_overlay').hide();
	$('#box_succ_register').hide();
}
function update_account_info(){
	var product_id = $('#product_id').val();
	act_pushUpdateInfo_GA();
	document.location='/updateaccount/index.'+product_id+'.html';
}
function trim_(text)
{
	var len=text.length;
	var i=0;
	var j=len-1;
	var s="";	
	while(text.charAt(i)==" ")
		i++;	
	while(text.charAt(j)==" ")
		j--;	
	if(i>j) 
		s="";
	else 
		s=text.substring(i,j+1);	
	return s;
}


